from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime
from app.models.document import DocumentStatus

class DocumentBase(BaseModel):
    """文档基础Schema"""
    title: str = Field(..., min_length=1, max_length=255)
    file_type: str
    tags: Optional[List[str]] = []
    category_id: Optional[str] = None
    knowledge_base_id: Optional[str] = None

class DocumentCreate(DocumentBase):
    """创建文档Schema"""
    file_name: str
    file_path: str
    file_size: int
    file_hash: str

class DocumentUpdate(BaseModel):
    """更新文档Schema"""
    title: Optional[str] = None
    tags: Optional[List[str]] = None
    category_id: Optional[str] = None
    knowledge_base_id: Optional[str] = None
    summary: Optional[str] = None

class DocumentResponse(BaseModel):
    """文档响应Schema"""
    id: str
    title: str
    file_name: str
    file_type: str
    file_size: int
    status: DocumentStatus
    upload_user_name: Optional[str]
    upload_time: datetime
    updated_at: Optional[datetime]
    page_count: Optional[int]
    word_count: Optional[int]
    summary: Optional[str]
    is_vectorized: bool
    tags: List[str] = []
    category_id: Optional[str] = None
    knowledge_base_id: Optional[str] = None
    
    class Config:
        from_attributes = True

class DocumentListResponse(BaseModel):
    """文档列表响应Schema"""
    total: int
    items: List[DocumentResponse]
    page: int
    page_size: int
